classes = [
    {"name": "abyss", "age": 25, "grade": "A"},
    {"name": "kin", "age": 23, "grade": "B"},
    {"name": "tian", "age": 24, "grade": "B"},
    {"name": "hun", "age": 26, "grade": "A"},
    {"name": "exe", "age": 21, "grade": "A"}
]

#第一题
def sort_age(x):
    return x['age']

print(sorted(classes, key=sort_age, reverse=False))
print(sorted(classes,key=lambda x:x['age'],reverse=True))

#第二题
def add_age(y):
    d={}
    d['age']=y['age']+1
    y.update(d)
    return y

hhh=list(map(add_age,classes))
print(hhh)

#第三题
def filter_classes(b):
    return b['grade']=='A'

print(list(filter(filter_classes,classes)))
print(list(filter(lambda c:c['grade']!='A',classes)))

#第4题
#定义斐波那契数列函数
def rec(n):
    if n<=1:
        return n
    else:
        return (rec(n-1)+rec(n-2))
#获取用户输入
nterms=int(input("你需要几位数？"))
#判断情况
if nterms<=0:
    print("请输入>0的正整数。")
else:
    print("以下是斐波那契数列：")
    for n in range(nterms):
        print(rec(n))
